import java.util.ArrayList;
import java.util.Hashtable;



class StateMonitor
{
	private Stateview s;
	private int maxHeight;

	public StateMonitor(Stateview s_in)
	{
		s = s_in;
		maxHeight = 0;
	}
	
	// setter and getter
	public void setMaxHeight(int h) {
		maxHeight = h;
	}
	
	public int getMaxHeight() {
		return maxHeight;
	}
	
	public Stateview getState() {
		return s;
	}
	
	/*
	 * Every state based on current piece is stored in a hash value
	 * Going through all different moves for the current piece
	 * every state is hashed into a integer:
	 * last digit[0-9]: represents the piece type
	 * second last digit[0-9]: represents the orientation
	 * the rest of digits: represent the slot number (from 0-19) 
	 * 
	 */
	public ArrayList<Stateview> generateStates() {
		ArrayList<Stateview> states = new ArrayList<Stateview>();
		
		// list all possible states
		int legalMoves[][] = s.legalMoves(); //legal moves for current state	
		for(int j=0; j<legalMoves.length; j++) {
			Stateview state = new Stateview();
			// copy top
			state.setTop(s.getTop());
			// copy field
			state.setField(s.getField());
			// copy piece
			state.setPiece(s.getNextPiece());
			// set pre state
			state.setPreRowsClear(s.getRowsCleared());

			// make a move		
			if(!state.makeMove(legalMoves[j][0], legalMoves[j][1]))
				continue;
			
			state.setStateValue(legalMoves[j][1]*100+legalMoves[j][0]*10+s.getNextPiece()); // set the move state
					
			states.add(state);			
		}
		
		return states;
	}

}